package com.losca.gulimall.auth.decorative;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Test {
    /**
     * 装饰者模式
     * https://note.youdao.com/s/JFDrEPcF
     * @param args
     */
    public static void test(String[] args) {
        //创建Beverage饮料，不加配料
        Beverage espresso = new Espresso();
        System.out.println(espresso.getDescription() + ","+espresso.cost());
        //加入牛奶
        espresso = new Milk(espresso);
        espresso = new Mocha(espresso);
        System.out.println(espresso.getDescription() + ","+espresso.cost());
    }

    /**
     * 列表删除李姓成员
     * @param args
     */
    public static void listDel(String[] args) {
        List<String> res = Arrays.asList("张三", "李四", "周一", "刘四", "李强", "李白");
        List<String> res2 = res.stream().filter((s) -> {
            return !s.startsWith("李");
        }).collect(Collectors.toList());
        System.out.println(res2);

    }

    /**
     *使用倒序删除
     * @param args
     */
    public static void listDel2(String[] args) {
        List<String> res = Arrays.asList("张三", "李四", "周一", "刘四", "李强", "李白");
        List<String> list = new ArrayList(res);
        for (int i = list.size()-1; i > 0; i--) {
            if (list.get(i).startsWith("李")){
                list.remove(i);
            }
        }
        System.out.println(list);
    }

}
